
import request from '@/utils/request';
export const getScriptList = (data: any) => {
  // 处理数组参数，将数组转换为字符串
  const processedData = { ...data };
  if (processedData.backups && Array.isArray(processedData.backups)) {
    processedData.backups = processedData.backups.join(',');
  }  
  // return new Promise((resolve, reject) => {
  //   return resolve({
  //     data: {
  //       code: '0',
  //       data: {
  //         total: 10,
  //         page: 1,
  //         paged: true,
  //         size: 20,
  //         search: '',
  //         totalPages: 1,
  //         results: [
  //           {
  //             action: 'IP地址',
  //             createdAt: '创建时间',
  //             isShow:'true',
  //             originalSystem: ['aa','bb','cc']
  //           },
  //         ],
  //       },
  //       message: '成功',
  //       timestamp: '2025-04-28T16:02:57+0800',
  //     },
  //   });
  // });
  return request({
    url: `/scriptlibrary/list`,
    method: 'get',
    params: processedData,
  });
};
export const seriptAdd = (data: any) => {
  // {
  //   "name": "第二个脚本", 
  //   "script_type": "Perl", 
  //   "description": "第二个脚本测试专用", 
  //   "tags": "运营发布", 
  //   "content": "#!/bin/bash\n echo `test`", 
  //   "version": "v0.1", 
  //   "version_desc": "test-no.3", 
  //   "is_public": true, 
  //   "creator": "admin" 
  //   }
  return request({
    url: `/scriptlibrary/add`,
    method: 'post',
    data,
  });
}
export const scriptUpdate = (data: any) => {
  return request({
    url: `/scriptlibrary/update`,
    method: 'put',
    data,
  });
}


export const seriptDel = (data: any) => {
  // {
  //   "id": "6cb66c67-b8a0-4b83-8147-00bf267a66bd", 
  //   }
  return request({
    url: `/scriptlibrary/delete`,
    method: 'delete',
    data,
  });
}

export const tagList = () => {
  return request({
    url: `/tag/list`,
    method: 'get',
  });
};
export const createTag = (data: any) => {
  return request({
    url: `/tag/create`,
    method: 'post',
    data,
  });
};
export const updateTag = (data: any) => {
  return request({
    url: `/tag/update`,
    method: 'put',
    data,
  });
};
export const deleteTag = (data: any) => {
  return request({
    url: `/tag/delete`,
    method: 'delete',
    data: data,
  });
};
export const scriptVersion = (data: any) => {
  console.log('[ data ] >', data)
  // 支持字符串ID或对象参数
  const id = typeof data === 'string' ? data : data?.id;
  return request({
    url: `/scriptlibrary/${id}/scriptVersion/list`,
    method: 'get',
  });
};

export const scriptVersionDel = (data: any) => {
  // 支持字符串ID或对象参数
  const id = typeof data === 'string' ? data : data?.id;
  return request({
    url: `/scriptlibrary/${id}/scriptVersion/delete`,
    method: 'delete',
    data,
  });
}
export const scriptVersionPublish = (data: any) => {
  // 支持字符串ID或对象参数
  const id = typeof data === 'string' ? data : data?.id;
  return request({
    url: `/scriptlibrary/${id}/scriptVersion/publish`,
    method: 'POST',
    data,
  });
}